(function () {
	var serverData = {};
    var serverTable;
    jQuery('.search_btn').on('click',function(){
    	clearQueryServerData();
    	getServerDate();
        serverTable.draw();
    });
    var getServerDate=function(){
    	if(jQuery("#orderArea").val()){
    		serverData.sSuperiorArea=jQuery("#orderArea").val().toString();
    		sSuperiorArea = jQuery("#orderArea").val().toString();
    	}
    	if(jQuery("#applyUser").val()){
    		serverData.applyUserName=jQuery("#applyUser").val().toString();
    		applyUserName = jQuery("#applyUser").val().toString();
    	}
    	if(jQuery("#type").val()){
    		serverData.kind=jQuery("#type").val().toString();
    		kind = jQuery("#type").val().toString();
    	}
    	if(jQuery("#startDate").val()){
    		serverData.applyDateStartDate=jQuery("#startDate").val().toString();
    		applyDateStartDate = jQuery("#startDate").val().toString();
    	}
    	if(jQuery("#endDate").val()){
    		serverData.applyDateEndDate=jQuery("#endDate").val();
    		applyDateEndDate = jQuery("#endDate").val().toString();
    	}
    	if(jQuery("#key").val()){
    		serverData.memo=jQuery("#key").val();
    		memo = jQuery("#key").val().toString();
    	}
    }
    var clearQueryServerData=function(){
    	if(serverData.sSuperiorArea) {
    		serverData.sSuperiorArea=null;
    		sSuperiorArea=null;
    	}
    	if(serverData.applyUserName) {
    		serverData.applyUserName=null;
    		applyUserName=null;
    	}
    	if(serverData.kind) {
    		serverData.kind=null;
    		kind=null;
    	}
    	if(serverData.applyDateStartDate) {
    		serverData.applyDateStartDate=null;
    		applyDateStartDate=null;
    	}
    	if(serverData.applyDateEndDate) {
    		serverData.applyDateEndDate=null;
    		applyDateEndDate=null;
    	}
    	if(serverData.memo) {
    		serverData.memo=null;
    		memo=null;
    	}
    }
  //初始化查询条件
    function initQueryParam(){
    	if($('#endDate').val()== "") 
    	$('#endDate').val(new Date().getFullYear()+"-"+((new Date().getMonth() + 1+"").length == 1 ? ("0"+(new Date().getMonth() + 1)) : new Date().getMonth() + 1) +"-"+new Date().getDate());
    	if($('#startDate').val() == "")
    	$('#startDate').val(new Date().getFullYear()+"-01-01");
    }
    jQuery(document).ready(function () {
    	$("#orderArea").multiselect({
		      header: true,
		      height: 175,
		      minWidth: 150,
		      classes: '',
		      checkAllText: '选中全部',
		      uncheckAllText: '取消全选',
		      noneSelectedText: '请勾选',
		      selectedText: '# 选中',
		      selectedList: 5,
		      show: null,
		      hide: null,
		      autoOpen: false,
		      multiple: true,
		      position: {},
		      appendTo: "body",
		      menuWidth:null
		    });
    	$("#applyUser").multiselect({
		      header: true,
		      height: 175,
		      minWidth: 150,
		      classes: '',
		      checkAllText: '选中全部',
		      uncheckAllText: '取消全选',
		      noneSelectedText: '请勾选',
		      selectedText: '# 选中',
		      selectedList: 5,
		      show: null,
		      hide: null,
		      autoOpen: false,
		      multiple: true,
		      position: {},
		      appendTo: "body",
		      menuWidth:null
		    });
    	$("#type").multiselect({
		      header: true,
		      height: 175,
		      minWidth: 150,
		      classes: '',
		      checkAllText: '选中全部',
		      uncheckAllText: '取消全选',
		      noneSelectedText: '请勾选',
		      selectedText: '# 选中',
		      selectedList: 5,
		      show: null,
		      hide: null,
		      autoOpen: false,
		      multiple: true,
		      position: {},
		      appendTo: "body",
		      menuWidth:null
		    });
    	getServerDate();
    	serverTable = jQuery('#dataTable').DataTable({
    		"serverSide": true,
            "ordering": false,
    		"ajax": {
    			"dataType": "json",
    			"type": "get",
    			"cache": false,
    			"url":window.rootPath+ '/ui/myMoneyTotal/getMyMoneyTotalPage',
    			"data": function (d) {
    				return $.extend({}, d, serverData);
    			}
    		},
    	    "columns" : [
				{
					data : null,
                    defaultContent : ""// 排序   1
				},
	            {
					data : 'applyUserName'
				},
	            {
					data : 'kind'
				},
	            {
					data : 'sSuperiorArea'
				},
				{
					data : 'money'
				},{
					data : 'applyDate',
                    render: function (data, type, full, meta) {
                        if (data)
                            return moment(data).format('YYYY/MM/DD');
                        else
                            return '';
                    }
				},
	            {
					data : 'memo'
				},
				{
					data: 'useContent'
				}],
			    "drawCallback": function (oSettings) {
			        var k = 0;
			        var total = oSettings.aiDisplay.length + oSettings._iDisplayStart;
			        for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
			            $('td:eq(0)', oSettings.aoData[oSettings.aiDisplay[k]].nTr).text(i + 1);
			            k++;
			        }
			    }	
	    	});
    });
})();